<!--
  - Copyright(c)  2022 厦门外里科技有限公司 All rights reserved.
  -
  - https://www.wailikeji.com
  -
  - 版权所有，侵权必究！
  -->

<template>
	<view class="panel">
		<view class="panel-content">
			<view class="wrap">
				<u-form class="form" :model="model" :rules="rules" ref="uForm">
					<u-form-item label="群名称" prop="name" label-width="180">
						<u-input v-model="model.name" placeholder="请输入群名称"></u-input>
					</u-form-item>
					<u-form-item label="群头像" prop="wxUrl" label-width="180">
						<u-upload :action="action" max-count="1" :multiple="false" :header="tokenObj"
							@on-success="wxUrlUploadSuccess"></u-upload>
					</u-form-item>
					<u-form-item label="群二维码" prop="qrcode" label-width="180">
						<u-upload :action="action" max-count="1" :multiple="false" :header="tokenObj"
							@on-success="qrcodeUploadSuccess"></u-upload>
					</u-form-item>
					<u-form-item label="群人数" prop="curNum" label-width="180">
						<u-input type="number" v-model="model.curNum" placeholder="请输入群人数"></u-input>
					</u-form-item>
					<u-form-item label="类型" prop="type" label-width="180">
						<u-radio-group v-model="model.type">
							<u-radio :name="0" >个人群</u-radio>
							<u-radio :name="1" >企业群</u-radio>
						</u-radio-group>
					</u-form-item>
				</u-form>
				<view class="form-footer">
					<u-button class="btn" type="primary" @click="submit">提交</u-button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		API_URL
	} from '@/env'
	import store from '@/common/store/index.js'
	let _this;
	export default {
		data() {
			return {
				model: {
					name: '',
					wxUrl: '',
					qrcode: '',
					curNum: '',
					type: 0
				},
				action: API_URL + "/common/oss/uploadQun",
				tokenObj: {
					"token": store.state.user.tokenInfo
				}
			};
		},
		mounted() {
			_this = this;
		},
		computed: {
			rules() {
				return {
					name: [{
						required: true,
						message: '请输入群名称',
						trigger: ['change', 'blur'],
					}],
					wxUrl: [{
						required: true,
						message: '请上传群头像',
						trigger: ['change', 'blur'],
					}],
					qrcode: [{
						required: true,
						message: '请上传群二维码',
						trigger: ['change', 'blur'],
					}],
					curNum: [{
						required: true,
						message: '请上传群人数',
						trigger: ['change', 'blur'],
					}]
				}
			}
		},

		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			wxUrlUploadSuccess(res, index, lists, name) {
				// this.model.wxUrl = res.fileName
				this.model.wxUrl = res.data.url
			},
			qrcodeUploadSuccess(res, index, lists, name) {
				// this.model.qrcode = res.fileName
				this.model.qrcode = res.data.url
			},
			submit() {
				this.$refs.uForm.validate(valid => {
					if (!valid) {
						this.$u.toast('您填写的信息有误，请根据提示修正。');
						return
					}
					this.$api.api('qunQrcode.add', this.model)
						.then(res => {
							if (res.code == 200) {
								uni.showToast({
									icon: 'none',
									position: 'bottom',
									title: '发布成功！'
								});
							} else {
								uni.showToast({
									icon: 'none',
									position: 'bottom',
									title: res.msg
								});
							}
						})
				});
			},
			cancel() {
				uni.navigateBack();
			}
		}
	};
</script>
<style lang="scss">
	@import '../../components/my/aidex.scss';

	page {
		background: #f5f5f5;
	}

	.u-form {
		background: #fff;
		padding: 0px 15px;
	}

	.remind-text {
		padding: 20rpx 30rpx;
		color: #666666;
	}


	.panel {
		padding: 0 30upx 0;
		// color: black;

		.panel-content {
			background: white;
			margin: 0 auto;
			border-radius: 16upx; //面包圆形倒角
			box-shadow: 0 2upx 20upx rgba(183, 183, 183, 0.3); //周边阴影
			margin-top: 16upx; //顶部间隔
		}
	}
</style>
